

package com.ourteam.education.dao.impl ;


import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.beanutils.PropertyUtils;

import org.springframework.jdbc.core.RowMapper;

import net.dao.AbstractSpringDAO;
import net.dao.DataAccessObjectHelper;


import com.ourteam.education.dao.Teacher;
import com.ourteam.education.dao.TeacherDAOQueryBean;
import com.ourteam.education.dao.ITeacherDAO;


/**
 * Template Name : DAO服务对象
 * Template Version : 1
 * Template Last Modfiy Date : Fri Nov 17 11:00:11 CST 2017
 * Auto Generate Date : 2019-09-22 15:15:11
  * Warning ! This file will be overwrite when regenerate !
  * 
 */

public class AbstractTeacherDAOJdbcImpl 
    extends AbstractSpringDAO implements ITeacherDAO{
    
            
    	
			
			
		
			
			
		
			
			
		
			
			
		
			
			
		
			
			
		
			
			
		
			
			
		
			
			
		
			
			
		
			
			
		
			
			
		
		
		
	    
    					
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
	
    public static final String[] ENTITY_FIELDS = new String[] { Id,TeacherName,TeacherGender,TeacherBirthday,ContactPhone,ContactsRelation,IdCardType,IdCardNum,SysAccountId,DeleteFlag,Status,Remarks };
	
	public static final String[] ENTITY_PROPERTIES = new String[] {_DataObjectProperty.Id,_DataObjectProperty.TeacherName,_DataObjectProperty.TeacherGender,_DataObjectProperty.TeacherBirthday,_DataObjectProperty.ContactPhone,_DataObjectProperty.ContactsRelation,_DataObjectProperty.IdCardType,_DataObjectProperty.IdCardNum,_DataObjectProperty.SysAccountId,_DataObjectProperty.DeleteFlag,_DataObjectProperty.Status,_DataObjectProperty.Remarks};
	
	public static final String[] ENTITY_PK_FIELDS = new String[] { Id };
	
	public static final String[] ENTITY_AUTO_GEN_PK_FIELDS = new String[] { Id };
	
	public static final String[] ENTITY_UNIQUE_FIELDS = new String[] {};
	
	private static String relatedJoinSQL = null;
	
	private static String basicFilterSQL = null;
	
	private DataAccessObjectHelper<Teacher, TeacherDAOQueryBean> daoHelper;
	
	public AbstractTeacherDAOJdbcImpl() {
		super();
		daoHelper = new DataAccessObjectHelper<Teacher, TeacherDAOQueryBean>(this);
	}
	
	protected String getEntityName() {
		return EntityName;
	}

	protected String[] getEntityFields() {
		return ENTITY_FIELDS;
	}

	protected String[] getEntityProperties() {
		return ENTITY_PROPERTIES;
	}

	protected String[] getEntityPKFields() {
		return ENTITY_PK_FIELDS;
	}
	
	protected String[] getEntityAutoGenPKFields(){
		return ENTITY_AUTO_GEN_PK_FIELDS;
	}
	
	
	protected String[] getEntityUniqueFields() {
		return ENTITY_UNIQUE_FIELDS;
	}
	
	protected String getBaiscQueryFilter(){
	
		if(basicFilterSQL == null){
                        StringBuffer basicFilterSQLbuffer = new StringBuffer();
						
			basicFilterSQLbuffer.append(DeleteFlag).append("=  0  ");
			
						
						
			basicFilterSQL = basicFilterSQLbuffer.toString();
		}
		
		return basicFilterSQL;
	}
	
	protected String getRelatedJoinSQL(){
		
		if(relatedJoinSQL == null){
			StringBuffer relatedJoinSQLBuffer = new StringBuffer();
			
						
			relatedJoinSQL = relatedJoinSQLBuffer.toString();
		}
		
		return relatedJoinSQL;
	}
	
    /**
	 * Check Data Unique
	 * @param aTeacher
	 * @throws Exception
	 */
	public boolean checkIsUnique(Teacher aTeacher) throws Exception{
	
		if(aTeacher == null){
			return true;
		}
	
		List valueList = new ArrayList();

		List pkValueList = new ArrayList();
		
		                
				
	    		
		pkValueList.add(aTeacher.getId());
				
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
				
		return isUnique(valueList.toArray(new Object[valueList.size()]), pkValueList
				.toArray(new Object[pkValueList.size()]));
	
	}
	
	/**
	 * Insert Data
	 * @param aTeacher
	 * @throws Exception
	 */
	public void insert(Teacher aTeacher) throws Exception{
		
						
		PropertyUtils.setProperty(aTeacher,_DataObjectProperty.DeleteFlag,org.apache.commons.beanutils.ConvertUtils.convert("0",int.class));
				
				
		super.doInsert(aTeacher);

	}

    /**
	 * Batch Insert Datas
	 * @param aTeacher
	 * @throws Exception
	 */
	public void batchInsert(Teacher[] aTeachers) throws Exception{
		
		 super.doBatchInsert(aTeachers);
		
	}

    /**
	 * Delete Data
	 * @param  final long id	 *
	 * @throws Exception
	 */
	public void delete( final long id ) throws Exception{

				
		Teacher tempTeacher = findById( id);
		
						
		PropertyUtils.setProperty(tempTeacher,_DataObjectProperty.DeleteFlag,org.apache.commons.beanutils.ConvertUtils.convert("1",int.class));
				
				
		update(tempTeacher);
				
	}
	
	/**
	 * Delete Datas
	 * @param queryBean 
	 * @throws Exception
	 */
	public void delete(TeacherDAOQueryBean queryBean) throws Exception{
	
				
		Teacher tempTeacher = new Teacher();
		
				
				
	    PropertyUtils.setProperty(tempTeacher,_DataObjectProperty.DeleteFlag,org.apache.commons.beanutils.ConvertUtils.convert("1",int.class));
				
				
		update(tempTeacher,queryBean);
				
	}
	
	public void delete(Teacher aTeacher) throws Exception {
				
				
									
						
					
				
		delete(aTeacher.getId());
		
	}
	
	/**
	 * Update Data Selective
	 * @param aTeacher
	 * @throws Exception
	 */
	public void update(Teacher aTeacher) throws Exception{
		
						
											
				
				
		if(aTeacher.getId() == 0){
			throw new Exception("Can not update object data whith out primary key value");
		}
				
		super.doUpdate(aTeacher);
		
		Teacher tempObj = findById(aTeacher.getId());
		
		if(tempObj != null){
			PropertyUtils.copyProperties(aTeacher, tempObj);
		}
	}
	
	/**
	 * Batch Update Datas
	 * @param aTeachers[]
	 * @throws Exception
	 */
	public void batchUpdate(Teacher[] aTeachers) throws Exception{
		
		super.doBatchUpdate(aTeachers);

	}

    /**
	 * Update Data By Condictions
	 * @param aTeacher
	 * @param aValueCriteria 
	 * @param aTransaction
	 * @throws Exception
	 */
	public void update(Teacher aTeacher, TeacherDAOQueryBean aQueryBean) throws Exception{
		
				
		super.doUpdateByQuery(aTeacher, aQueryBean);
		
	}
	
	/**
	 * Update Data By Condictions
	 * @param aQueryBean
	 * @throws Exception
	 */
	public void update(TeacherDAOQueryBean aQueryBean) throws Exception {
		super.doUpdateByQuery(aQueryBean);
	}


    protected void checkNullValue(Teacher aTeacher) throws Exception{	
																																																												
	}
	
	/**
	 * Get Data By ID
	 * @param  final long id	 * @return  ${businessObject.name}
	 * @throws Exception
	 */
	public Teacher findById( final long id) throws Exception{
		
		    	                
    	    	                		
		TeacherDAOQueryBean queryBean = new TeacherDAOQueryBean();
		
		TeacherDAOQueryBean.Criteria  criteria = queryBean.createCriteria();
	
		                

		criteria.andIdEqualTo(id);
        
        
		//queryBean.setDistinct(true);
		
		Teacher[] Teachers = query(queryBean);
		
		if(Teachers.length == 0){
			return null;
		}
		else{
			return Teachers[0];
		}
		
	}

    /**
	 * Query Data
	 * @param queryBean
	 * @return Teacher[]
	 * @throws Exception
	 */
	public Teacher[] query(TeacherDAOQueryBean queryBean) throws Exception{
				
		List result = super
				.doQuery(queryBean, new JdbcTeacherRowMapper());

		return (Teacher[]) result.toArray(new Teacher[result.size()]);
	}
	
	/**
	 * Query ${businessObject.name} Selective
	 * @param queryBean
	 * @return Map[]
	 * @model
	 * @throws Exception
	 */
	public Map<String,Object>[] querySelective(TeacherDAOQueryBean queryBean)  throws Exception{
		
		if(queryBean.getSelectProperties().isEmpty()){
			queryBean.addAllSelectProperties();
		}
		
		return super.doQuerySelective(queryBean);
		
	}
	
	/**
	 * Query Data Count
	 * @param queryBean
	 * @return int
	 * @throws Exception
	 */
	public int queryCount(TeacherDAOQueryBean queryBean) throws Exception{
		
		return super.doQueryCount(queryBean);
		
	}
	
	public void synchronize(Teacher[] aTeachers, TeacherDAOQueryBean queryBean)
			throws Exception {
		daoHelper.synchronize(aTeachers,queryBean);
		
	}

	public void synchronize(Teacher[] aTeachers,
			TeacherDAOQueryBean queryBean,
			net.dao.IDataAccessInterface.ISynchronizeCallback<Teacher> callBack)
			throws Exception {
		daoHelper.synchronize(aTeachers,queryBean,callBack);
	}

    
     public static class JdbcTeacherRowMapper implements
			RowMapper<Teacher> {

		public Teacher mapRow(ResultSet resultSet, int arg1) throws SQLException {
			Teacher object = new Teacher();

			int columnIndex = 1;
			
			int __dataType;
			
			try{
													
	            	            
				Object id = null;
				
								
				id =  resultSet.getObject(columnIndex++);
				
				               
				object.setIdNull(resultSet.getBoolean(columnIndex++));
				
				if(id != null){
				
                    setBeanValue(object, _DataObjectProperty.Id,id);
				}
				
					
	            	            
				Object teacherName = null;
				
								
				teacherName =  resultSet.getObject(columnIndex++);
				
				               
				object.setTeacherNameNull(resultSet.getBoolean(columnIndex++));
				
				if(teacherName != null){
				
                    setBeanValue(object, _DataObjectProperty.TeacherName,teacherName);
				}
				
					
	            	            
				Object teacherGender = null;
				
								
				teacherGender =  resultSet.getObject(columnIndex++);
				
				               
				object.setTeacherGenderNull(resultSet.getBoolean(columnIndex++));
				
				if(teacherGender != null){
				
                    setBeanValue(object, _DataObjectProperty.TeacherGender,teacherGender);
				}
				
					
	            	            
				Object teacherBirthday = null;
				
								
				__dataType = resultSet.getMetaData().getColumnType(columnIndex);
				
				if(__dataType == java.sql.Types.DATE || __dataType == java.sql.Types.TIME || __dataType == java.sql.Types.TIMESTAMP){
					teacherBirthday = resultSet.getTimestamp(columnIndex++);
				
				}
				else{
					teacherBirthday =  resultSet.getObject(columnIndex++);
				
				}
				
				               
				object.setTeacherBirthdayNull(resultSet.getBoolean(columnIndex++));
				
				if(teacherBirthday != null){
				
                    setBeanValue(object, _DataObjectProperty.TeacherBirthday,teacherBirthday);
				}
				
					
	            	            
				Object contactPhone = null;
				
								
				contactPhone =  resultSet.getObject(columnIndex++);
				
				               
				object.setContactPhoneNull(resultSet.getBoolean(columnIndex++));
				
				if(contactPhone != null){
				
                    setBeanValue(object, _DataObjectProperty.ContactPhone,contactPhone);
				}
				
					
	            	            
				Object contactsRelation = null;
				
								
				contactsRelation =  resultSet.getObject(columnIndex++);
				
				               
				object.setContactsRelationNull(resultSet.getBoolean(columnIndex++));
				
				if(contactsRelation != null){
				
                    setBeanValue(object, _DataObjectProperty.ContactsRelation,contactsRelation);
				}
				
					
	            	            
				Object idCardType = null;
				
								
				idCardType =  resultSet.getObject(columnIndex++);
				
				               
				object.setIdCardTypeNull(resultSet.getBoolean(columnIndex++));
				
				if(idCardType != null){
				
                    setBeanValue(object, _DataObjectProperty.IdCardType,idCardType);
				}
				
					
	            	            
				Object idCardNum = null;
				
								
				idCardNum =  resultSet.getObject(columnIndex++);
				
				               
				object.setIdCardNumNull(resultSet.getBoolean(columnIndex++));
				
				if(idCardNum != null){
				
                    setBeanValue(object, _DataObjectProperty.IdCardNum,idCardNum);
				}
				
					
	            	            
				Object sysAccountId = null;
				
								
				sysAccountId =  resultSet.getObject(columnIndex++);
				
				               
				object.setSysAccountIdNull(resultSet.getBoolean(columnIndex++));
				
				if(sysAccountId != null){
				
                    setBeanValue(object, _DataObjectProperty.SysAccountId,sysAccountId);
				}
				
					
	            	            
				Object deleteFlag = null;
				
								
				deleteFlag =  resultSet.getObject(columnIndex++);
				
				               
				object.setDeleteFlagNull(resultSet.getBoolean(columnIndex++));
				
				if(deleteFlag != null){
				
                    setBeanValue(object, _DataObjectProperty.DeleteFlag,deleteFlag);
				}
				
					
	            	            
				Object status = null;
				
								
				status =  resultSet.getObject(columnIndex++);
				
				               
				object.setStatusNull(resultSet.getBoolean(columnIndex++));
				
				if(status != null){
				
                    setBeanValue(object, _DataObjectProperty.Status,status);
				}
				
					
	            	            
				Object remarks = null;
				
								
				remarks =  resultSet.getObject(columnIndex++);
				
				               
				object.setRemarksNull(resultSet.getBoolean(columnIndex++));
				
				if(remarks != null){
				
                    setBeanValue(object, _DataObjectProperty.Remarks,remarks);
				}
				
								
								
				return object;
			}catch(Exception e){
				throw new SQLException(e.getMessage());
			}
		}

	}
	
}